package com.scau.microblogverse.controller;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Starsky
 * @since 2025-10-27
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "用户登录接口，用于验证用户身份")
    public Map<String, Object> login(
            @ApiParam(name = "username", value = "用户名", required = true)
            @RequestParam String username,
            @ApiParam(name = "password", value = "密码", required = true)
            @RequestParam String password) {

        Map<String, Object> result = new HashMap<>();

        // 这里应该是实际的登录验证逻辑
        // 为了测试Swagger，我们简单处理
        if ("admin".equals(username) && "123456".equals(password)) {
            result.put("code", 200);
            result.put("message", "登录成功");
            result.put("token", "fake-token-" + System.currentTimeMillis());
        } else {
            result.put("code", 401);
            result.put("message", "用户名或密码错误");
        }

        return result;
    }

    @PostMapping("/register")
    @ApiOperation(value = "用户注册", notes = "用户注册接口，用于用户注册账号")
    public Map<String, Object> register(
            @ApiParam(name = "username", value = "用户名", required = true)
            @RequestParam String username,
            @ApiParam(name = "password", value = "密码", required = true)
            @RequestParam String password) {

        Map<String, Object> result = new HashMap<>();

        // 这里应该是实际的注册逻辑
        // 为了测试Swagger，我们简单处理
        if ("admin".equals(username)) {
            result.put("code", 400);
            result.put("message", "用户名已存在");
        }
        else {
            result.put("code", 200);
            result.put("message", "注册成功");
        }
        return result;
            }
}
